<template>
  <div id="teacher-work-load">
    <div
      class="wrapper-container"
      style="display: flex; flex-direction: column; width: 1711px"
    >
      <div class="search-container">
        <div class="search-container-left">
          <div
            class="search-container-item"
            v-for="(select, index) in selectList"
            :key="index"
          >
            <div v-if="select.type === 'select'" class="box">
              <span v-show="select.name">{{ select.name }}</span>

              <el-select
                v-model="select.val"
                style="width: 90px"
                size="mini"
                placeholder="请选择"
                clearable
              >
                <el-option
                  v-for="item in select.valList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </div>
            <div class="box" v-if="select.type === 'data'">
              <span class="demonstration" v-show="select.name">{{
                select.name
              }}</span>
              <el-date-picker
                v-model="select.val"
                type="date"
                placeholder="选择日期"
                prefix-icon="aaa"
              >
              </el-date-picker>
            </div>
            <div v-if="select.type === 'MultiSelect'" class="box"></div>
            <div v-if="select.type === 'btn'" class="box">
              <span class="demonstration" v-show="select.name">{{
                select.name
              }}</span>
              <el-input
              style="width:120px"
                v-model="select.val"
                placeholder="请输入内容"
              ></el-input>
            </div>
            <div v-if="select.type === 'selectTree'" class="box">
              <span v-show="select.name">{{ select.name }}</span>
              <el-popover
                trigger="click"
                placement="bottom"
                v-model="showUnitTree"
                style="cursor: pointer;"
                width="120">
                <div style="max-height: 260px;overflow-y: auto;">
                <el-tree
                      default-expand-all
                      node-key="id"
                      :data="select.valList"
                      :expand-on-click-node="false"
                      :props="props"
                      @node-click="toShowUnitInfo">
                </el-tree>
                </div>
                <el-input slot="reference" v-model="select.val" class="selectTree"
                    clearable style="width: 120px;" suffix-icon="el-icon-arrow-down">
                </el-input>
              </el-popover>
            </div>
          </div>

          <div style="margin-left:40px">
            <el-button type="warning" icon="el-icon-notebook-2" size="mini" plain @click="getJysPkqktj">统计</el-button>
          </div>
        </div>
      </div>
    </div>

    <div class="assessment-container">
      <div class="table-container">
        <el-table
          :data="tableData"
          border
          class="table-data"
          row-class-name="row-class"
          cell-class-name="cell-class"
          header-row-class-name="header-row-class"
          header-cell-class-name="header-cell-class"
          style="height: calc(100vh - 340px); overflow-y: auto"
        >
          <el-table-column prop="name" label="任课教员" align="center">
          </el-table-column>
          <el-table-column
            prop="bx"
            label="单位"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="jszc"
            label="职称"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="courseName"
            label="授课课程"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="jxb"
            label="上课班次"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="hours"
            label="课时数"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="totalHours"
            label="总计"
            align="center"
          ></el-table-column>
        </el-table>
      </div>
    </div>
    <div class="wrapper-container" style="width:calc(100% - 20px)">
      <div class="export-button" @click="exportData()">
        <img src="../../../../assets/assessment/icon-export.png" alt="" />
        <span>&ensp;导出Excel</span>
      </div>
      <div class="bottom-block" style="display: block">
        <div class="text">当前共找到{{ total }}条记录,当前显示{{ startPage }}-{{ endPage }}条</div>
      </div>
      <div class="pagination-block">
        <el-pagination
          prev-text="上一页"
          next-text="下一页"
          :page-size="pageSize"
          layout="prev, pager, next, jumper"
          :total="total"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import { static_getGzl, queryCommonXueqi, queryCommonDept,static_exportGzl, queryDefaultXueQi } from "@/api/trainingManagement/place.js";
import ButtonItem from "@/components/ButtonItem.vue";

export default {
  components: {
    ButtonItem,
  },
  data() {
    return {
      total: 1, //总条数
      pageSize: 50, //条数
      startPage: 1, //开始条数
      endPage: 1, //结束条数
      currentPage: 1, //当前页数
      selectList: [
        {
          type: "select",
          name: "学期:",
          val: "",
          valList: [],
        },
        {
          type: "selectTree",
          name: "单位:",
          val: "",
          valList: [],
        },
        {
          type: "btn",
          name: "教员名称:",
          val: "",
        },
      ],
      props:{
        children: "children",
        label: "name",
      },
      tableData: [],
      jsonFields: {
        任课教员: "name",
        单位: "bx",
        职称: "zjmc",
        授课课程: "courseName",
        上课班次: "jxb",
        课时数: "hours",
        总计: "totalHours"
      },
      treeOptionList: [], //单位下拉树
      showUnitTree: false, //
      unitId: "", //单位id
    };
  },
  created() {},
  mounted() {
    this.getDefaultXueQi();
    this.queryCommonXueqi();
    this.queryCommonDept();
    // this.getJysPkqktj();
  },
  methods: {
    async getDefaultXueQi(){
      queryDefaultXueQi().then(res=>{
        if(res.data.code == 200){
          this.selectList[0].val = res.data.data;
        }
      }).then(()=>{
        this.getJysPkqktj()
      })
    },
    exportData() {
      var name = this.selectList[2].val;
      // var gzdw = this.unitId;
      var gzdw = '';
      var xueqi = this.selectList[0].val;
      static_exportGzl(name, xueqi, gzdw).then((res) => {
        /** 获取生成设置好的文件名 */
        /** 接收文件流 */
        const blob = new Blob([res.data]);
        let url = URL.createObjectURL(blob);
        /** 模拟浏览器操作Document，并模拟下载动作 */
        let link = document.createElement("a");
        link.style.display = "none";
        link.href = url;
        link.setAttribute("download", "教员工作量统计.xlsx");
        document.body.appendChild(link);
        link.click();
      });
    },
    async queryCommonDept() {
      const res = await queryCommonDept();
      if (res.data.code == 200) {
        this.selectList[1].valList = res.data.data;
        // this.selectList[1].val = this.selectList[1].valList[0].name;
        // this.unitId = this.selectList[1].valList[0].id;
      }
    },
    toShowUnitInfo(data) {
      this.selectList[1].val = data.name;
      this.unitId = data.id;
      this.showUnitTree = false;
        // this.query();
      },
    // 获取学期列表
    async queryCommonXueqi() {
      const res = await queryCommonXueqi();
      if (res.data.code == 200) {
        this.selectList[0].valList = res.data.data;
        // this.selectList[0].val = this.selectList[0].valList[0].id;
      }
    },
    // 查询不排课统计
    async getJysPkqktj() {
      var name = this.selectList[2].val;
      var gzdw = this.unitId;
      var xueqi = this.selectList[0].val;
      const res = await static_getGzl(name, xueqi, gzdw);
      if (res.data.code == 200) {
        this.tableData = res.data.data.records;
        this.total = res.data.data.total;
        var length = this.tableData.length;
        this.calculatePage(
          this.pageSize,
          res.data.data.current, length);
      }
    },
    // 计算开始和结束条数
    calculatePage(pageSize, current, length) {
      if (current == 1) {
        if (length != 0) {
          this.startPage = 1;
          this.endPage = length;
        }
      } else {
        this.startPage = pageSize * (current - 1) + 1;
        this.endPage = parseInt(this.startPage)  + parseInt(length) - 1;
      }
    },
  },
  computed: {}, //计算属性
};
</script>
<style lang="less" scoped>
@import "../../../../styles/text.less";
/deep/ .szjky .el-dialog__body {
  height: 432px;
}
.pagination-block {
  margin-top: 20px;
  display: flex;
  flex-direction: row;
  justify-content: center;
}
</style>
<style lang="less" scoped>
@import "../../../../styles/supervision.less";

/deep/ .table-container {
  .el-table td,
  .el-table th.is-leaf,
  .el-table--border,
  .el-table--group {
    border-color: #c7d7eb;
  }

  .el-table__header tr,
  .el-table__header th {
    padding: 0;
    height: 76px;
    background-color: #edf2f9;
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    line-height: 20px;
    color: #004ca7;
  }

  .el-table__body tr,
  .el-table__body td {
    padding: 0;
    height: 86px;
  }

  .wrapper-button {
    display: flex;
    flex-direction: column;
    align-items: center;

    > div {
      margin-bottom: 8px;
    }
  }
  .table-data {
    width: 100%;
    border: 0.8px solid #004ca7;
    /*border-radius: 9px;*/
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #004ca7;
  }
}

.wrapper-container .search-container .search-container-left {
  width: 100%;
  flex-wrap: wrap;
  .search-container-item {
    width: 12%;
    margin-right: 0px;
    .box {
      > span {
        text-align: left;
      }
      display: flex;
      justify-content: space-evenly;
      margin-bottom: 20px;
      align-items: center;
      /deep/ .el-input__inner {
        height: 28px;
      }
    }
  }
}

/deep/.el-date-editor.el-input {
  width: 110px;
}
/deep/ .el-input--medium {
  width: 110px;
  .el-input__inner {
    height: 28px;
    width: 110px;
    padding: 0px 18px;
  }
}
/deep/ .el-table thead {
  color: #004ca7 !important;
}

.btn {
  margin-top: 271px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 271px;
  .submit {
    width: 84px;
    height: 27px;
    line-height: 8px;
  }
}
.export-button {
  cursor: pointer;
  width: 127px;
  height: 27px;
  background: #fff6ef;
  border: 1px solid #f3b815;
  border-radius: 4px;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  margin-top: 14px;
  > img {
    width: 17px;
    height: 17px;
  }
  > span {
    margin-left: 12px;
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #f3b815;
  }
}

.search-button {
  width: 77px;
  height: 28px;
  line-height: 28px;
  background: #f1f8fe;
  border: 1px solid #51aef6;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  > span {
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #51aef6;
  }
  > img {
    width: 20px;
    height: 20px;
    margin-right: 4px;
  }
}

.mar-lef-2 {
  margin-left: 20px;
}
.undeLine {
  text-decoration: underline;
  cursor: pointer;
}
.assessment-container {
  width: 1711px;
  .table-container {
     width: 1711px;
  }
}

/deep/ .el-tree-node {
  color: #004ca7;
}

.assessment-container {
  width: calc(100% - 20px);
  .table-container {
     width: 100%;
  }
}
</style>


<style lang="less" scoped>
  #teacher-work-load{
    /deep/ .el-button--warning.is-plain{
      background: #FFF6EF;
      border-color: #F3B815;
      color: #F3B815;
      border-radius: 6px;
    }
    /deep/ .el-button--warning.is-plain:focus, .el-button--warning.is-plain:hover{
      color: #F3B815;
      background: #FFF6EF;
      border: 1px solid #F3B815;
      border-radius: 6px;
    }

    /deep/ .el-button--success.is-plain{
      background: #F1FFF8;
      border-color: #02C86C;
      color: #02C86C;
      border-radius: 6px;
    }
    /deep/ .el-button--success.is-plain:hover{
      background: #F1FFF8;
      border: 1px solid #02C86C;
      color: #02C86C;
      border-radius: 6px;
    }

    /deep/ .el-button--primary.is-plain{
      background: #F1F8FE;
      border-color: #51AEF6;
      color: #51AEF6;
      border-radius: 6px;
    }

    /deep/ .el-button--primary.is-plain:hover{
      background: #F1F8FE;
      border: 1px solid #51AEF6;
      color: #51AEF6;
      border-radius: 6px;
    }

    /deep/ .el-button--danger.is-plain{
      background: #FFEFEF;
      border-color: #FF3819;
      color: #FF3819;
      border-radius: 6px;
    }

    /deep/ .el-button--danger.is-plain:hover{
      background: #FFEFEF;
      border: 1px solid #FF3819;
      color: #FF3819;
      border-radius: 6px;
    }
  }
</style>
